// import axios from 'axios'
import * as api from '../../../http/api'
import http from '../../../http/http'

const state={
  pageCount:0,
  postTypeSearchsData:[],
  postTypeAddsData:[],
  postTypeChangesData:[],
  postTypeDeletesData:[],
  postTypePagingsData:[]
}
const actions={
  // 查询消耗品类型
  postTypeSearchData({commit},obj){
    console.log(obj)
    return http({
      url:api.consumablesTypeManagementSelect,//更改接口名 已修改
      method:'post',
      data:obj
    }).then(res=>{
      console.log(res.data)
      // commit('storeTypeSearchData',res.data.conditionTypeSelectOfPage)//注意data到底是什么
      commit('storeTypeSearchData',res.data)
      return res.code
    })
  },
  // 新增消耗品类型
  postTypeAddData({commit},obj){
    console.log(obj)
    return http({
      url:api.consumablesTypeManagementAdd,//更改接口名
      method:'post',
      data:obj
    }).then(res=>{
      commit('storeTypeAddData',res.data)//注意data到底是什么
      return res.code
    })
  },
  // 修改消耗品类型
  postTypeChangeData({commit},obj){
    console.log(obj)
    return http({
      url:api.consumablesTypeManagementUpdate,
      method:'post',
      data:obj
    }).then(res=>{
      console.log(res)
      commit('storeTypeChangeData',res.data)
      return res.code
    })
  },
  // 删除消耗品类型
  postTypeDeleteData({commit},obj){
    console.log(obj)
    return http({
      url:api.consumablesTypeManagementDelete,
      method:'post',
      data:obj
    }).then(res=>{
      console.log(res)
      commit('storeTypeDeleteData',res.data)
      return res.code
    })
  },
  //消耗品类型分页
  postTypePagingData({commit},obj){
    console.log(obj)
    return http({
      url:api.consumablesTypeManagementPage,
      method:'post',
      data:obj
    }).then(res=>{
      console.log(res.data)
      commit('storeTypePagingData',res.data)
      return res.code
    })
  }
}
const mutations={
  storeTypeSearchData(state,obj){
    state.pageCount=obj.pageCount
    state.postTypeSearchsData=obj.conditionTypeSelectOfPage
  },
  storeTypeAddData(state,obj){
    state.postTypeAddsData=obj
  },
  storeTypeChangeData(state,obj){
    state.postTypeChangesData=obj
  },
  storeTypeDeleteData(state,obj){
    state.postTypeDeletesData=obj
  },
  storeTypePagingData(state,obj){
    state.pageCount=obj.pageCount
    state.postTypePagingsData=obj.takeOut
  }
}
const getters={
  getPageCount(state){
    return state.pageCount
  },
  getstoreTypePagingData(state){
    state.postTypePagingsData.forEach(item=>{
      let mydelFlag = {}
      if(item.delFlag===0) {
        mydelFlag = {
          value: 0,
          label: '正常'
        }
      } else if(item.delFlag===1) {
        mydelFlag = {
          value: 1,
          label: '删除'
        }
      }
      item.delFlag = mydelFlag
    });
    return state.postTypePagingsData
  },
  getstoreTypeDeleteData(state){
    state.postTypeDeletesData.forEach(item=>{
      let mydelFlag = {}
      if(item.delFlag===0) {
        mydelFlag = {
          value: 0,
          label: '正常'
        }
      } else if(item.delFlag===1) {
        mydelFlag = {
          value: 1,
          label: '删除'
        }
      }
      item.delFlag = mydelFlag
    });
    return state.postTypeDeletesData
  },
  getstoreTypeChangeData(state){
    state.postTypeChangesData.forEach(item=>{
      let mydelFlag = {}
      if(item.delFlag===0) {
        mydelFlag = {
          value: 0,
          label: '正常'
        }
      } else if(item.delFlag===1) {
        mydelFlag = {
          value: 1,
          label: '删除'
        }
      }
      item.delFlag = mydelFlag
    });
    return state.postTypeChangesData
  },
  getstoreTypeAddData(state){
    state.postTypeAddsData.forEach(item=>{
      let mydelFlag = {}
      if(item.delFlag===0) {
        mydelFlag = {
          value: 0,
          label: '正常'
        }
      } else if(item.delFlag===1) {
        mydelFlag = {
          value: 1,
          label: '删除'
        }
      }
      item.delFlag = mydelFlag
    });
    return state.postTypeAddsData
  },
  getstoreTypeSearchData(state){
    state.postTypeSearchsData.forEach(item=>{
      let mydelFlag = {}
      if(item.delFlag===0) {
        mydelFlag = {
          value: 0,
          label: '正常'
        }
      } else if(item.delFlag===1) {
        mydelFlag = {
          value: 1,
          label: '删除'
        }
      }
      item.delFlag = mydelFlag
    });
    return state.postTypeSearchsData
  }
}

export default{
  namespaced:true,
  state,
  actions,
  mutations,
  getters
}